package edu.zut.cs.software.example.shop.dao;

import java.util.List;

import javax.transaction.Transactional;


import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import edu.zut.cs.software.example.dao.GenericDao;
import edu.zut.cs.software.example.market.domain.Product;
import edu.zut.cs.software.example.shop.domin.Shop;

public interface ShopDao extends GenericDao<Shop,Long>{
	/**
	 * Used to login to verify user identity
	 * @param shopname
	 * @param bussinessname
	 * @return
	 */
	@Query(value="  SELECT * FROM `example`.`t_shop`",nativeQuery = true)
	public List<Shop> getByShopnamebusinessname() ;
	
	/**
	 * Used to get basic information about the user
	 * @return
	 */
	@Query(value="  SELECT * FROM `example`.`t_shop` WHERE `shopID`=?1 ",nativeQuery = true)
	public Shop getAllShop(@Param("shopID") String shopID);
	@Query(value = "  SELECT count(*) FROM `example`.`t_shop` WHERE `businessname` LIKE CONCAT('%',?1,'%') ", nativeQuery = true)
	public int getShopCounts(@Param("shopname") String shopname);
	
	
	@Query(value = "  SELECT count(*) FROM `example`.`t_shop` WHERE `studentid` = ?1 ", nativeQuery = true)
	public int getShopByStudentIdCounts(@Param("studentid") Long studentid);
	
	
	@Query(value = "  SELECT * FROM `example`.`t_shop` WHERE `shopID` LIKE CONCAT('%',?1,'%')  LIMIT ?2,?3 ", nativeQuery = true)
	public List<Shop> getShop(@Param("shopname")String shopname,@Param("pagenum") int pagenum,@Param("pageSize") int pageSize);
	
	
	
	@Query(value="  SELECT * FROM example.t_shop LIMIT ?1,?2",nativeQuery = true)
	public  List<Shop> getByShop( @Param("pageStart") int pageStart,@Param("pageSize") int pageSize) ;
	
	
	
	@Query(value = "  SELECT count(*) FROM `example`.`t_shop`  ", nativeQuery = true)
	public int getshopCounts();
	
	
	
	@Modifying
	@Transactional
	@Query(value = "  DELETE FROM `example`.`t_shop` WHERE  `shopID`=?1", nativeQuery = true)
	public int deleteShopID(@Param("shopID") String shopID);
	
	//public int showEditDialogs();
	
	
	@Query(value = "  SELECT * FROM `example`.`t_shop` WHERE `studentid`= ?1 LIMIT ?2,?3 ", nativeQuery = true)
	public List<Shop> findByStudentId(@Param("studentid")Long studentid,@Param("pagenum") int pagenum,@Param("pageSize") int pageSize);
	
	@Query(value = "  SELECT * FROM `example`.`t_shop` WHERE `ID`=?1", nativeQuery = true)
	public Shop getUpdateShop(@Param("ID")int id);
	
	@Query(value = " UPDATE `example`.`t_shop` SET shopname=:shopname , shopaddress=:shopaddress,shopID=:shopID WHERE ID=:id ", nativeQuery = true)
	@Modifying
	@Transactional
	public int editShop(@Param("shopname")String shopname,@Param("shopaddress")String shopaddress,@Param("shopID")String shopID,@Param("id")Long id);
	
	/**
	 * 
	 * @param 
	 * @return Shop
	 */
	public Shop findBybusinessname(String businessname);
	
	/**
	 * 
	 * @param shop1
	 * @return boolean
	 */
	public boolean existsByBusinessname(String businessname);


}